package controller;

import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import manager.MesManager;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import to.OrderTO;

public class MesCtr extends MultiActionController {
	private MesService service;

	public MesCtr(MesService service) {
		this.service = service;
	}

	public ModelAndView orderList(HttpServletRequest request,
			HttpServletResponse response) throws SQLException {
		//service에서 order목록 불러오기
		ArrayList<OrderTO> list = service.getOrderList();
		HttpSession session = request.getSession();
		session.setAttribute("orderList", list);
		//web에 목록 출력
		return new ModelAndView("OrderList");
	}

	public ModelAndView machineNow(HttpServletRequest request,
			HttpServletResponse response) throws SQLException {
		//service에서 machine 작동 현황 받아오기
		ArrayList<OrderTO> list = service.getWorkerList();
		//web에 작동 여부 출력
		return new ModelAndView("jsonview", "workerList", list);
	}
	
	public ModelAndView machineResult(HttpServletRequest request, HttpServletResponse response, OrderTO oto) throws SQLException{
		//service에서 작업 결과 받아오기
		MesManager manager = service.getOutcomeList(oto.getOrderId());
		manager.setOrderId(oto.getOrderId());
		//web에 결과 출력
		return new ModelAndView("jsonview", "manager", manager);
	}
	
	public ModelAndView resultPage(HttpServletRequest request, HttpServletResponse response, OrderTO oto) throws SQLException{
		//service에서 작업 결과 받아오기
		MesManager manager = service.getOutcomeList(oto.getOrderId());
		manager.setOrderId(oto.getOrderId());
		//web에 결과 출력
		return new ModelAndView("jsp/report", "manager", manager);
	}
}
